package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.base.pojo.PageQueryModel;
import com.coding.dao.PaintDao;
import com.coding.pojo.Paint;
import com.coding.service.PaintService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/8/16
 **/
@Service
public class PaintImpl implements PaintService {
    @Autowired
    PaintDao paintDao;
    @Override
    public void selectById(int paint_id, BaseModel baseModel) throws Exception {
        Paint paint=paintDao.selectByPrimaryKey(paint_id);
        if (paint!=null){
            baseModel.setSucceed("成功获取诗画",paint);
        }else {
            baseModel.setFailure("获取诗画失败");
        }
    }

    @Override
    public void selectList(PageQueryModel pageQueryModel, BaseModel baseModel) throws Exception {
        PageHelper.startPage(pageQueryModel.getPage(), pageQueryModel.getSize());
        List<Paint > paintList=paintDao.selectList();
        PageInfo pageInfo = new PageInfo(paintList);
        paintList = pageInfo.getList();
        if (paintList.size() == 0) {
            if (pageInfo.getPageNum() > 1) {
                baseModel.setFailure("已经没有下一页了");
            } else {
                baseModel.setOther(2, "没有符合条件的诗画");
            }
            return;
        }
        baseModel.setSucceed("查询成功，符合条件的诗画共" + paintList.size() + "个", paintList);
    }
}
